package com.myapp;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.myapp.dao.RoleDao;
import com.myapp.model.Role;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		setup();
		
		ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
		
//		UserInfoDaoImpl dao = new UserInfoDaoImpl();
//		UserInfo userInfo = new UserInfo();
//		userInfo.setFirstName("Paul");
//		userInfo.setLastName("Smith");
//		Address address = new Address();
//		address.setPostalCode("1234");
//		address.setProvince("Cordoba");
//		address.setCity("Cordoba");
//		address.setStreet("Ave.Colon");
//		userInfo.setAddress(address);
//		dao.saveUserInfo(userInfo);
//		
//		List<UserInfo> list = dao.findAll();
//		for(UserInfo ui : list){
//			System.out.println(ui);
//		}
		
		RoleDao roleDao = (RoleDao) context.getBean("roleDao");
		Role role = new Role();
		role.setName("manager");
		role.setDescription("Manager role");
		roleDao.saveRole(role);
		
		List<Role> roles = roleDao.findAll();
		for(Role r : roles){
			System.out.println(r);
		}
		
	}
	
	public static void setup(){
//		// table UserInfo
//        HibernateUtil.droptable("drop table UserInfo");
//        HibernateUtil.setup("create table UserInfo(id int, firstname VARCHAR(20), lastName VARCHAR(20), email VARCHAR(20), phoneNumber VARCHAR(20), webSite VARCHAR(20))");
//        // table Role
//        HibernateUtil.droptable("drop table Role");
//        HibernateUtil.setup("create table Role(id int, name VARCHAR(20), description VARCHAR(20))");
	}
}
